import 'package:flutter/material.dart';
import 'package:wk_weather/utils/MyLogTool.dart';

class ColorUtils {

  static Color parseColorStrToColor(String code) {
    Color result =Colors.white;
    var value = 0 ;
    if (code.contains("#")) {
      try {
        value = int.parse(code.substring(1), radix: 16);
      } catch (e) {
        weatherPrint(e.toString());
      }
      switch (code.length) {
        case 1 + 6://6位
          result = Color(value + 0xFF000000);
          break;
        case 1 + 8://8位
          result = Color(value);
          break;
        default:
          result =Colors.white;
      }
    }else {
      try {
        value = int.parse(code, radix: 16);
      } catch (e) {
        weatherPrint(e.toString());
      }
      switch (code.length) {
        case  6:
          result = Color(value + 0xFF000000);
          break;
        case  8:
          result = Color(value);
          break;
        default:
          result =Colors.white;
      }
    }
    return result;
  }


}

